package wigiri.team.info.copy;

import wigiri.team.info.Activator;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * Most of this code is from <code>JavaBasePreferencePage</code>
 * 
 */
public class CopyPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
	private Text prefixText;
	private IPreferenceStore store;

	public CopyPreferencePage() {
		super();
		// TODO Auto-generated constructor stub
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
		setDescription("SynchView multi-file preference");
		store = getPreferenceStore();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createContents(Composite parent) {
		// TODO Auto-generated method stub
		initializeDialogUnits(parent);

		// Outmost container
		Composite result = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout(2, false);
		
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
		layout.marginWidth = 20;
		layout.verticalSpacing = convertVerticalDLUsToPixels(10);
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
		result.setLayout(layout);
		
		Label lb = new Label(result, 0);
		lb.setText("Path Prefix ");
		
		GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
		prefixText = new Text(result, SWT.BORDER);
		prefixText.setEditable(true);
		prefixText.setLayoutData(gridData);
		prefixText.setText(store.getString("PREFIX_PATH"));
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
	 */
	public void init(IWorkbench workbench) {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
	 */
	protected void performDefaults() {
		// TODO Auto-generated method stub
		//IPreferenceStore store = getPreferenceStore();
//		System.out.println("performDefaults > store.getDefaultString(\"PREFIX_PATH\") :" + store.getDefaultString("PREFIX_PATH"));
		prefixText.setText(store.getDefaultString("PREFIX_PATH"));
		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
	 */
	public boolean performOk() {
		// TODO Auto-generated method stub
		//IPreferenceStore store = getPreferenceStore();
//		System.out.println("performOk > prefixText.getText() :" + prefixText.getText());
		store.setValue("PREFIX_PATH", prefixText.getText());
//		for (int i = 0; i < fCheckBoxes.size(); i++) {
//			Button button = (Button) fCheckBoxes.get(i);
//			String key = (String) button.getData();
//			store.setValue(key, button.getSelection());
//		}

		return super.performOk();
	}

}